package com.wuhongyu.base;

import com.wuhongyu.common.MyCommon;
import com.wuhongyu.util.MyUtil;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

/**
 * Base实现类
 * @param <E>
 */
public class BaseServiceImpl<E> implements BaseService<E> {


    private BaseDao<E> dao;

    public void setBaseDao(BaseDao<E> dao){
        this.dao = dao;
    }

    @Override
    public Page<E> findAll(E e, Integer number) {
        return dao.findAll(new PageRequest(MyUtil.getCurrentPage(number), MyCommon.PAGESIZE));

    }

    @Override
    public void save(E e) {
        dao.saveAndFlush(e);
    }

    @Override
    public void delete(Integer id) {
        dao.deleteById(id);
    }

    @Override
    public E findOne(Integer id) {
        return dao.getOne(id);
    }
}
